﻿using System;
using System.Runtime.InteropServices;

namespace Zhaoxi.CANController
{
    internal class Program
    {
        // 基于CAN控制器(需要使用Win32,非托管资源)
        // 前提是:主板上有 CAN 模块
        // WinCE 系统
        // 1、需要进行硬件接口的创建
        [DllImport("coredll.dll")]
        public static extern uint CreateFile(string FileName,
                                             uint DesiredAccess,
                                             uint ShareMode,
                                             uint SecurityAttributes,
                                             uint CreationDisposition,
                                             uint FlagsAndAttributes,
                                             int hTemplateFile);

        [DllImport("coredll.dll")]
        public static extern int CloseHandle(uint hDevice);

        // ARM主板提供的 驱动  CAN  主板型号:EM9000、EM9260
        // 非托管方式调用
        // 发送帧
        [DllImport("CAN_API_DLL.dll")]
        public static extern bool CAN_SendFrame(uint hDevice, byte[] TxFrameBuffer);

        // 接收下一帧
        [DllImport("CAN_API_DLL.dll")]
        public static extern bool CAN_GetNextReceivedFrame(uint hDevice, byte[] RxFrameBuffer);

        // 启动
        [DllImport("CAN_API_DLL.dll")]
        public static extern bool CAN_StartChip(uint hDevice);

        // 停止
        [DllImport("CAN_API_DLL.dll")]
        public static extern bool CAN_StopChip(uint hDevice);

        // 波特率
        [DllImport("CAN_API_DLL.dll")]
        public static extern bool CAN_SetBaudRate(uint hDevice, byte[] index);

        // 点对点  滤波
        [DllImport("CAN_API_DLL.dll")]
        public static extern bool CAN_SetGlobalAcceptanceFilter(uint hDevice, byte[] AcceptanceFilter, byte size);


        static void Main(string[] args)
        {
            // CAN1  CAN2
            //var CANhandle = CreateFile(strPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);

            // CreateFile   --   Win32的底层(非托管的方式)
        }
    }
}
